This page last changed on Feb 15, 2007 by makh_dv@qarea.com.

Maybe it is not "correct way". But for me it really works.
I used CppUnit 1.12.0

First Server...

Server

Tasks

In <exec> and .bat file for launching tests.
It is required that this but file first delete privious results.
Than launch tests and using XmlOutputter, put results at "Results.xml"

<exec>
    	<executable>TestRunner.bat</executable>
    	<baseDirectory>***</baseDirectory>
    	<buildTimeoutSeconds>10</buildTimeoutSeconds>
</exec>

Publisher

I like that build can be identified by NUnit, so I use the same method.
And send to NUnit, exe file that return 1 or 0, depend on result.
It has something

int main(int argc, char* argv[])
{
...
	// Return error code 1 if the one of test failed.
	return wasSucessful ? 0 : 1;
}

It is a usual way for CppUnit. Who used cppUnit just once, should know these strings.

Then I add to log recieved results.

<nunit>
    	<path>IsSucessful.exe</path>
    	<assemblies>
		<assembly>*noassembly*</assembly>
	</assemblies>
	<outputfile>empty.xml</outputfile>
</nunit>
<merge>
	<files>
		<file>Results.xml</file>
	</files>
</merge>
<xmllogger />

Now build failds if CppUnit tests failed.

Lets update results at Dashboard...

Dashboard

I've updated unittests.xsl , to make tests in usual manner.
Changed unittests.xsl is attached - unittests.xsl.

How cppUnit xml looks.

You can find standart example at cppunit-cvs-1.12.0\contrib\xml-xsl\tests.xml.
In same folder xsl-transformation for cppUnit to JUnit, but I don't know how to use "double transformation" for CC.NET dashboard.

And here is my example

<TestRun>
  <FailedTests>
    <FailedTest id="5">
      <Name>MyMathOperationsTest::testAdd</Name>
      <FailureType>Assertion</FailureType>
      <Location>
        <File>c:\test_cc\demon\cpp\src\tests4prj\mymathoperationstest.cpp</File>
        <Line>28</Line>
      </Location>
      <Message>equality assertion failed
- Expected: 10
- Actual  : 11
</Message>
    </FailedTest>
    <FailedTest id="6">
      <Name>MyMathOperationsTest::testDivideThrow</Name>
      <FailureType>Error</FailureType>
      <Message>uncaught exception of unknown type
</Message>
    </FailedTest>
  </FailedTests>
  <SuccessfulTests>
    <Test id="1">
      <Name>MoneyTest::testConstructor</Name>
    </Test>
    <Test id="2">
      <Name>MoneyTest::testEqual</Name>
    </Test>
    <Test id="3">
      <Name>MoneyTest::testAdd</Name>
    </Test>
    <Test id="4">
      <Name>MoneyTest::testAddThrow</Name>
    </Test>
  </SuccessfulTests>
  <Statistics>
    <Tests>6</Tests>
    <FailuresTotal>2</FailuresTotal>
    <Errors>1</Errors>
    <Failures>1</Failures>
  </Statistics>
</TestRun>

Variables

<!-- CppUnit Cases -->
	<xsl:variable name="cppunit.result.list" select="/cruisecontrol/build/TestRun"/>
	<xsl:variable name="cppunit.failed.list" select="$cppunit.result.list/FailedTests/FailedTest"/>
	<xsl:variable name="cppunit.failed.count" select="count($cppunit.failed.list)"/>
	<xsl:variable name="cppunit.passed.list" select="$cppunit.result.list/SuccessfulTests/Test"/>
	<xsl:variable name="cppunit.passed.count" select="count($cppunit.passed.list)"/>
<!-- CppUnit Statistics -->
	<xsl:variable name="cppunit.case.count" select="$cppunit.result.list/Statistics/Tests"/>
	<xsl:variable name="cppunit.failure.count" select="$cppunit.result.list/Statistics/Failures"/>
	<xsl:variable name="cppunit.error.count" select="$cppunit.result.list/Statistics/Errors"/>

Update Test Statistic

<!-- "Old" 
	<xsl:variable name="total.time" select="$nunit2.time + $junit.time"/>
	<xsl:variable name="total.notrun.count" select="$nunit2.notrun.count"/>
	<xsl:variable name="total.run.count" select="$nunit2.case.count + $junit.case.count - $total.notrun.count"/>
	<xsl:variable name="total.failure.count" select="$nunit2.failure.count + $junit.failure.count + $junit.error.count"/> 
-->
    
<!-- Added CppUnit-->
	<xsl:variable name="total.time" select="$nunit2.time + $junit.time"/>
	<xsl:variable name="total.notrun.count" select="$nunit2.notrun.count"/>
	<xsl:variable name="total.run.count" select="$cppunit.case.count + $nunit2.case.count + $junit.case.count - $total.notrun.count"/>
	<xsl:variable name="total.failure.count" select="$cppunit.failed.count + $nunit2.failure.count + $junit.failure.count + $junit.error.count"/>

For know it is absent testTime for cpp unit, but you can add "Chrono-plugin" if it is major for you.

Short Details

First add "apply-templates"

<!-- Short Information *Next Line added* -->
<xsl:apply-templates select="$cppunit.failed.list"/>
<!-- Next line helps you to identify the place -->		
<xsl:apply-templates select="$junit.error.list"/>
<xsl:apply-templates select="$junit.failure.list | $nunit2.failure.list"/>
<xsl:apply-templates select="$nunit2.notrun.list"/>

Then add template before "<!-- Unit Test Errors -->"

<!-- CppUnit Failed Test -->
	<xsl:template match="FailedTest">
        <tr>
            <xsl:if test="position() mod 2 = 0">
                <xsl:attribute name="class">section-oddrow</xsl:attribute>
            </xsl:if>
            <td class="section-data">CppUnit <xsl:value-of select="FailureType"/></td>
            <td class="section-data"><xsl:value-of select="Name"/></td>
        </tr>
    </xsl:template>

Detailed Informaton

First add "call-template"

<!-- Detailed Information *Next Lines added* -->
<xsl:call-template name="cppunittestdetail">
	<xsl:with-param name="detailnodes" select="$cppunit.failed.list"/>
</xsl:call-template>
<!-- Next line helps you to identify the place -->
<xsl:call-template name="junittestdetail">
	<xsl:with-param name="detailnodes" select="//testsuite/testcase[.//error]"/>
</xsl:call-template>

Then add template before "<!-- JUnit Test Errors And Failures Detail Template -->"

<xsl:template name="cppunittestdetail">
	<xsl:param name="detailnodes"/>

	<xsl:for-each select="$detailnodes">
        
		<tr><td class="section-data">CppTest:</td><td class="section-data"><xsl:value-of select="Name"/></td></tr>
		<tr><td class="section-data">Type:</td><td class="section-data"><xsl:value-of select="FailureType"/></td></tr>
		<tr><td class="section-data">Message:</td><td class="section-data"><pre style="font-size=120%"><xsl:value-of select="Message"/></pre></td></tr>
            
		<xsl:if test="count(Location) > 0">
			<tr>
				<td></td>
 				<td class="section-error">
					<pre><xsl:value-of select="Location/File"/>: Line <xsl:value-of select="Location/Line"/></pre>
				</td>
			</tr>
		</xsl:if>

		<tr><td colspan="2"><hr size="1" width="100%" color="#888888"/></td></tr>

        </xsl:for-each>
</xsl:template>

If you done all rigth - Now it should all work.
Modified file you can find in attaches - unittests.xsl, all this inderts marked by (DEmon)

ToDo

  • Start using cppunit2junit.xsl transformation from CppUnit package at Dashboard. If someone could help... please do it. I'm not ASP.net developer.
  • Learn NUnit plugin and create "tidy" plugin for CppUnit.

unittests.xsl (application/octet-stream)
Document generated by Confluence on Mar 14, 2009 02:55